package cate.game.role.pay.limittimeggift;

import cate.common.table.limittimegift.LimitTimeGiftRow;
import cate.game.GameBody;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteField;
import org.springframework.data.annotation.Transient;

public class CheapItemPO{
    public CheapItemPO() {
    }

    @Transient
    @JsonIgnore
    public GameBody game;

    @NoteField(value = "礼包tid")
    public int tid;

    @NoteField(value = "购买数量")
    public int purchaseNum;

    @NoteField(value = "礼包生成时间", detail = "")
    public long activeTime;

    @JsonIgnore
    @NoteField(value = "礼包跨天跨周跨月成功", detail = "")
    public boolean recycle;

    public CheapItemPO(GameBody game) {
        this.game = game;
    }

    @JsonIgnore
    public LimitTimeGiftRow getRow() {
        return game.table.limitGift.gift.get(tid);
    }

    @JsonIgnore
    public boolean expired() {
        LimitTimeGiftRow row = getRow();
        if (row == null) {
            return true;
        }
        return activeTime + row.packDuration < System.currentTimeMillis();
    }

    public long getExpiredTime() {
        LimitTimeGiftRow row = getRow();
        if (row == null) {
            return 0L;
        }
        return activeTime + row.packDuration;
    }

    public void initialize(GameBody game) {
        this.game = game;
    }
}
